﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>权限管理 - 功能实体管理</title>

    <#include "/pages/include/head.ftl" />
    <#import "/pages/import/helper.ftl" as h />
	<!--tree组件样式-->
	<#include "/pages/include/tree-css.ftl" />
	<script>
	</script>
    
    <style type="text/css">
      .tree-left-height{height:510px;}
    </style>
</head>
<body>

<div id="right-content">
<div class="page-top-bar">
<ul class="path">帐号管理<span>&gt;</span>系统绑定帐号</ul>
</div>
<div class="function-bar">
<ul class="form-function">
</ul>
</div>
<div class="list-container">
<div class="tree-left"><h1>系统列表</h1><div id="treeLeft" class="tree-left-height">

   <@s.url var="actionUrl" action="tree" namespace="/widgets" />
	<script>
	$(function(){
		var utree = $("#tree").ajaxTree({
			url:'${actionUrl}',
			beforeLoad : function(e, treeNode, tree){
				tree.setLoadParas({
					id : treeNode.data.id
						,treeModelBean:'bizSystemTreeModel'
						,parentProperty:'id'
						,idProperty:'id'  	//节点ID属性
						,textProperty:'name'  //节点名称属性
				});
			}
		});
		utree.bind('nodeClick',function(e, treeNode){
			var nodeId = treeNode.data.id;
			 var sdata={};
	         sdata["criteria.id"] = nodeId;
             $('#accountSystemGrid').trigger("grid-filter", sdata);
             $("input[name='system_id']").val(nodeId);
		});
	});
</script>

<div id="tree"></div>
</div></div>
<div class="tree-right" id="treeRight">

<div class="list-container"  style="float:left;">
<div class="list-search">
<form id="search_form" name="search_form">
<ul>
<li>帐户名称：<input name="criteria.username"/></li>
<li>真实姓名：<input name="criteria.realName"/></li>
<li class="search-btn-area">
      <div class="btn-order">
        <ul>
          <li class="left-normal" id="btn1_11"></li>
          <li id="submit" class="middle-normal"><img src="${contextPath}/images/ico16/ico-search.gif" alt="查询" />查 询</li>
          <li class="right-normal" id="btn1_13"></li>
       </ul>
      </div>
	</li>
</ul>
</form>
<script>
<!-- lingen.liu 由于此页面Grid的加载依靠左边树的选择进行过滤，因此不能使用默认搜索，默认搜索导致左边系统选择过滤失效，因此重写此方法 -->
$(function(){ 
   $('#submit').click(function(){
				var sdata={};
				var params = $('#search_form').serializeArray();
				for(var index in params){
					var name = params[index].name;
					var value = params[index].value;
					if(value!=null && value!="")
					sdata[name] = value;
				}
			 sdata["criteria.id"] = $("input[name='system_id']").val();
	    $('#accountSystemGrid').trigger("grid-filter", sdata);
   });
});
</script>
</div>

<!--工具栏-->
<div class="toolbar">
  <ul> 
    <li><a id="btn_bindAccounts"><img src="${contextPath}/images/ico16/group_link.gif" alt="添加绑定" title="添加绑定" /><span>添加绑定</span></a></li>
    <li><a id="btn_unBindAccounts"><img src="${contextPath}/images/ico16/link_break.gif" alt="解除绑定" title="解除绑定" /><span>解除绑定</span></a></li>
    <li id="menu1"><a id="btn_changeStatus"><img src="${contextPath}/images/ico16/ico_commission_16.gif" alt="设置用状态" border="0" title="设置状态" /> 设置状态</a></li>
  </ul>
 </div>
<!--结束-->

<!-- grid start -->
<input type="hidden" name="system_id"/>

<@rw.grid 
    	id="accountSystemGrid" 
    	caption="帐户" 
    	dataType="json" 
    	pager="true" 
    	width="600"
    	gridModel="gridModel"
    	multiselect="true"
    	rowList="10,15,20"
    	rowNum="10"
    	rownumbers="true"
    	onSelectRowTopics="rowselect"
    	onGridCompleteTopics="grid-complete">
    	<@sj.gridColumn name="username" 		index="username"		title="帐户名称" />
        <@sj.gridColumn name="realName" 			index="realName"			title="用户真实姓名" 	sortable="false"/>
        <@sj.gridColumn name="email" 			index="email"			title="E-Mail" 	sortable="false"/>
        <@sj.gridColumn name="bizSystemBindings.0.status" index="bizSystemBindings.0.status" title="状态" formatter="icon"/>       

</@rw.grid>

<!-- lingen.liu 绑定用户的JDialog -->
<@sj.dialog  
        id="systemBindAccounts"  
        buttons="{  
                '确定':function() { systemBindAccounts();$(this).dialog('close'); }, 
                '取消':function() { $(this).dialog('close'); }  
                }"  
        autoOpen="false"  
        modal="true"  
        title="添加帐号绑定" 
        width="700"
        height="400"
    > 
 <!-- lingen.liu 添加绑定弹出界面的搜索框 -->
<div class="list-search">
<form id="add_account_search" name="add_account_search">
<ul>
<li>帐户名称：<input name="criteria.username"/></li>
<li>真实姓名：<input name="criteria.realName"/></li>
<li class="search-btn-area">
      <div class="btn-order">
        <ul>
          <li class="left-normal" id="btn1_11"></li>
          <li id="add_account_search_submit" class="middle-normal"><img src="${contextPath}/images/ico16/ico-search.gif" alt="查询" />查 询</li>
          <li class="right-normal" id="btn1_13"></li>
       </ul>
      </div>
	</li>
</ul>
</form>
<script>
<!-- lingen.liu 添加绑定的搜索框方法 -->
$(function(){ 
   $('#add_account_search_submit').click(function(){
				var sdata={};
				var params = $('#add_account_search').serializeArray();
				for(var index in params){
					var name = params[index].name;
					var value = params[index].value;
					if(value!=null && value!="")
					sdata[name] = value;
				}
			 sdata["criteria.id"] = $("input[name='system_id']").val();
	    $('#systemAccountBindingGrid').trigger("grid-filter", sdata);
   });
});
</script>
</div>

  <!--列表-->
<div id="grid" class="border-lbr">
    <@rw.grid 
	id="systemAccountBindingGrid"
	caption="帐号信息" 
	pager="true"
	gridModel="gridModel"
	rowList="10,15,20"
	rowNum="10"
	rownumbers="true"
	multiselect="true"
	width="600"
	onGridCompleteTopics="grid-complete">
    <@sj.gridColumn name="username" 		index="username"		title="帐户名称" />
    <@sj.gridColumn name="realName" 			index="realName"			title="用户真实姓名" 	sortable="false"/>
    <@sj.gridColumn name="email" 			index="email"			title="E-Mail" 	sortable="false"/>
</@rw.grid>
</@sj.dialog>


<!-- 状态设置的JDialog -->
<@sj.dialog  
        id="resetStatu"  
        buttons="{  
                '确定':function() { resetStatus();$(this).dialog('close'); }, 
                '取消':function() { $(this).dialog('close'); }  
                }"  
        autoOpen="false"
        modal="true"  
        title="状态设置" 
    > 
    
    <input type="hidden" name="resetStatu_id"/>
     <table cellpadding="0" cellspacing="0" class="form-2column">
  <tr>
      <th height="50">有效状态：</th>
      <td ><input type="radio" name="radiobutton" value="1">
        启用
        <input type="radio" name="radiobutton" value="0">
        停用</td>
    </tr>
</table>
</@sj.dialog>
<!-- grid end -->

<div id="grid" class="border-lbr"></div>
</div>
</div>
</div>
</div>
</body>

 <script>
   $(function(){
       <!-- lingen.liu 打开帐号绑定界面 -->
       $('#btn_bindAccounts').click(function(){
           var system_id =  $("input[name='system_id']").val();
           if(system_id==""){
              alert("未选中系统");
              return;
           }
           
           var sdata={};
	       sdata["criteria.id"] = system_id;
           $('#systemAccountBindingGrid').trigger("grid-filter", sdata);
           $('#systemBindAccounts').dialog('open');
       });
       
    
    <!-- lingen.liu 删除一个系统同一些帐号的绑定  -->
    $('#btn_unBindAccounts').click(function(){
       var systemId = $("input[name='system_id']").val();
       var accountselectedIds = $("#accountSystemGrid").jqGrid('getGridParam','selarrrow');
       if(accountselectedIds.length==0){
             alert("未选中需要解除绑定的帐号");
             return;
        }
        var yes = confirm("确认解除绑定?");
        if(yes){
        var reqParams = {id:accountselectedIds,systemIds:systemId};
         $.ajax({                                                
          type: "POST",                                     
          url: "paramAccount-systemUnBindAccounts.action",                                   
          data: reqParams,   
          success: function(msg){
             alert("ok,成功解除绑定");
             $('#accountSystemGrid').trigger("reloadGrid");
          } 
        });
        }
    });
  
  <!-- lingen.liu 点击设置状态，进行必要的检验及弹出设置状态界面 -->
  $('#btn_changeStatus').click(function(){
      var accountselectedIds = $("#accountSystemGrid").jqGrid('getGridParam','selarrrow');
        if(accountselectedIds==""){
           alert("未选中帐号");
           return;
        }
        
        if(accountselectedIds.length>1){
           alert("只能选中一个帐号进行此操作");
           return;
        }
        
       $("input[name='resetStatu_id']").val(accountselectedIds);
       $('#resetStatu').dialog('open');
  });
  
  });
  
  
  <!-- lingen.liu 修改一个帐号绑定的某个系统设置为可用或不可用 -->
  function resetStatus(){
    var id = $("input[name='resetStatu_id']").val();
    var systemId = $("input[name='system_id']").val();
    var statu = $("input[name='radiobutton']:checked").val();
    var reqParams = {id:id,systemIds:systemId,status:statu};
    
     $.ajax({                                                
          type: "POST",                                     
          url: "paramAccount-resetLock.action",                      
          data: reqParams,   
          success: function(msg){
             alert("状态修改成功");
             $("#accountSystemGrid").trigger("reloadGrid");
          } 
        });
  }
  
   <!-- lingen.liu 将当前系统及用户选中的帐号绑定起来  -->
   function systemBindAccounts(){ 
      var systemId = $("input[name='system_id']").val();
      var accountIds = $("#systemAccountBindingGrid").jqGrid('getGridParam','selarrrow');
          if(accountIds==""){
            alert("未选中任何帐号");
            return;
          }else{
            var yes = confirm("确认添加这些绑定？");
            if(yes){
        var reqParams = {id:accountIds,systemIds:systemId};
        $.ajax({
          type: "POST",
          url: "paramAccount-systemBindAccounts.action",                                   
          data: reqParams,
          success: function(msg){
             alert("OK，绑定成功");
             $("#accountSystemGrid").trigger("reloadGrid");
          }
        });
      }}
   }
</script>
</html>